﻿'
' Will Strohl (will.strohl@gmail.com)
' http://www.willstrohl.com
' http://dnntweet.codeplex.com
'
' Copyright (c) 2011, Will Strohl
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this 
' software and associated documentation files (the "Software"), to deal in the Software 
' without restriction, including without limitation the rights to use, copy, modify, 
' merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 
' permit persons to whom the Software is furnished to do so, subject to the following 
' conditions:
'
' The above copyright notice and this permission notice shall be included in all copies 
' or substantial portions of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
' INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 
' PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
' HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 
' OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
'

Imports System.Web
Imports System.Web.SessionState

Namespace WillStrohl.Modules.Twitter

    Public Class SearchHandler
        Implements System.Web.IHttpHandler, IRequiresSessionState

#Region " Private Members "

        Private p_SearchTerms As String = Null.NullString
        Private p_AuthorSaidText As String = Null.NullString

#End Region

#Region " Properties "

        Private ReadOnly Property SearchTerms() As String
            Get
                Return Me.p_SearchTerms
            End Get
        End Property

        Private ReadOnly Property AuthorSaidText() As String
            Get
                Return Me.p_AuthorSaidText
            End Get
        End Property

#End Region

        Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest

            context.Response.ContentType = "text/plain"

            If Not context.Request.QueryString("st") Is Nothing Then
                Me.p_SearchTerms = context.Request.QueryString("st").ToString
            Else
                Throw New ArgumentNullException("st")
            End If

            If Not context.Request.QueryString("as") Is Nothing Then
                Me.p_AuthorSaidText = context.Request.QueryString("as").ToString
            Else
                Throw New ArgumentNullException("as")
            End If

            context.Response.Write(SearchAPI.GetSearchResults(Me.SearchTerms, Me.AuthorSaidText))
            context.Response.End()

        End Sub

#Region " IHttpHandler Implementation "

        ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
            Get
                Return False
            End Get
        End Property

#End Region

    End Class

End Namespace